package com.yhd.controller;

import com.yhd.entity.dto.CourseBookedDto;
import com.yhd.entity.dto.CourseDto;
import com.yhd.entity.dto.SystemDictionaryDto;
import com.yhd.entity.query.CourseBookedVO;
import com.yhd.entity.result.ResultVo;
import com.yhd.model.ResultPage;
import com.yhd.service.CourseService;
import com.yhd.service.CycleImgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@Api(value = "小程序活动相关")
@Slf4j
@RequestMapping(value = "/app/Activity")
@CrossOrigin
public class AppActivityController extends WebBaseController {

    @Autowired
    private CycleImgService cycleImgService;
    @Autowired
    private CourseService courseService;
    
    @ApiOperation(value = "活动列表", httpMethod = "GET",  notes = "")
    @ApiImplicitParams({@ApiImplicitParam(name = "name", value = "课程名称", required = false, paramType = "字符串"),
            @ApiImplicitParam(name = "activityStatus", value = "活动状态：0=未开始，1=进行中，2=已结束", required = false, paramType = "int"),
            @ApiImplicitParam(name = "classifyId", value = "分类id", required = false, paramType = "int"),
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, paramType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示数量", required = true, paramType = "int"),
            @ApiImplicitParam(name = "startTime", value = "报名开始时间", required = false),
            @ApiImplicitParam(name = "endTime", value = "报名结束时间", required = false)})
    @GetMapping("/list")
    @ResponseBody
    public ResultVo<ResultPage<List<CourseDto>>> courseList(String name, Integer activityStatus, String classifyId, Integer pageSize, Integer pageNum,String startTime, String endTime) {
        ResultPage<List<CourseDto>> result = courseService.getActivityList(name, activityStatus, classifyId, pageSize, pageNum, startTime, endTime);
        return ResultVo.success(result);
    }

    @ApiOperation(value = "活动分类列表", httpMethod = "GET",  notes = "")
    @GetMapping("/classList")
    @ResponseBody
    public ResultVo<List<SystemDictionaryDto>> classList() {
        List<SystemDictionaryDto> result = courseService.getActivityListClassList();
        return ResultVo.success(result);
    }
    
    
    @ApiOperation(value = "活动详情", httpMethod = "GET",notes = "")
	@ApiImplicitParams({@ApiImplicitParam(name = "courseId", value = "课程id", required = true, paramType = "int")})
    @GetMapping("/detail")
    @ResponseBody
    public ResultVo<CourseDto> activityDetail(@RequestParam Integer courseId) {
        CourseDto result = courseService.activityDetail(courseId, getUserInfo(request));
        return ResultVo.success(result);
    }
    
    @ApiOperation(value = "活动报名", httpMethod = "POST", notes = "{\n" +
            "  \"courseId\": \"课程id\"\",\n" +
            "  \"subType\": \"类型：1=免费，0=直接购买\"\",\n" +
            "  \"isAgreeAgreement\": \"是否同意课程协议 1是 0否\"\",\n" +
            "  \"sex\": \"性别 0女 1男\"\",\n" +
            "  \"userName\": \"用户名\"\",\n" +
            "  \"cardType\": \"证件类型\"\",\n" +
            "  \"cardNo\": \"证件号码\"\",\n" +
            "  \"birthday\": \"生日\"\",\n" +
            "  \"phone\": \"电话\"\",\n" +
            "  \"company\": \"公司\"\",\n" +
            "  \"position\": \"职位\"\",\n" +
            "  \"position\": \"职位\"\",\n" +
            "  \"tuser\": \"招生老师\"\",\n" +
            "  \"referrerUser\": \"推荐人\"\n" +
            "}")
    @PostMapping("/order")
    @ResponseBody
    public ResultVo<CourseBookedDto> order(@RequestBody CourseBookedVO bookedVO) throws Exception {
        if (getUserInfo(request) == null) {
            return ResultVo.failure("10001","无访问权限，请先登录！");
        }
        bookedVO.setType("activity");
        return courseService.order(bookedVO, getUserInfo(request));
    }

}
